import React,{useState,useEffect} from 'react'

const baseUrl = `https://cnodejs.org/api/v1`
const useList =()=>{
    const [list, setList] = useState([]);
    const [loading, setLoading] = useState(false);
    const [tab,setTab] = useState('');//tab是一个变量

    const handleTab = (tab)=>setTab(tab);//第一个tab仅为形参

    useEffect(() => {
        setLoading(true);
        fetch(`${baseUrl}/topics?tab=${tab}&page=${1}`)
            .then(res => res.json())
            .then(res => {
                console.log(res)
                setList(res.data);
                setLoading(false);
            })
    }, [tab])

    return [list,loading,handleTab]
}
export default useList